package pkg.chemdrm;
import javax.microedition.khronos.opengles.GL10;

import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;



public class EntityTorch extends Sprite implements Entity {
	private final static float FLICKER_FREQUENCY = 100;
	private final static float RED = 200f/255f;
	private final static float GREEN = 64f/255f;
	private final static float BLUE = 10f/255f;
	
	private final float mPhase = (float) (Math.random()*2*Math.PI); // this makes sure they aren't all flickering in unison.
	
	private float mLifetime = 0;

	
	public EntityTorch(float pX, float pY, float pWidth, float pHeight, TextureRegion pTextureRegion) {
		super(pX, pY, pWidth, pHeight, pTextureRegion);
		
		setBlendFunction(GL10.GL_ONE, GL10.GL_ONE);
		
		setColor(RED, GREEN, BLUE); 
	}

	public void update(float dt) {
		mLifetime += dt;
		
		setColor((float)(Math.abs((RED-100f/255f)*Math.sin(FLICKER_FREQUENCY*mLifetime + mPhase)) + (100f/255f)), (float)(Math.abs((GREEN - 32f/255f)*Math.sin(FLICKER_FREQUENCY*mLifetime + mPhase)) + (32f/255f)), BLUE);
		
	}

	public boolean getExists() {
		return true;
	}

	
	
}
